Published on: Mon Apr 05 2010
Enumeration Typesenum color {red,blue,green,yellow}color is the tag name “enum color” is the type You can give variables this type, and assign them values from the set you described
enum color c1,c2; c1 = greenThat just declared two variables of type enum color. Say you get bored of typing on enum color all the time. You can define the type using typedef.
typedef int newIntTypeThat just created a new type of interger variable type called newIntType. Enum stores things as intergers. For example, in the color example, red corresponds to 0, blue to 1 and so on…
enum day{sun,mon,tues,wednes,thurs,fri,sat}; typedef enum day days; days today = fri; switch (today) { case fri: //And so on…. }Enums are good for switch cases! Storage class Variables have two attributes, type and storage class. Storage class in how and where memory is allocated. There are four types in C. auto(matic), extern, register, static. Auto – Used for local variables, kept on the stack Extern – global variables, present until the program stops running, not kept in Stack. Register – defaults to auto if necessary, kept on the processor chip. Very special and used to improve execution speed, treated as advice only.